package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabTatNode;
import com.ysd.lis.mapper.lab.LabTatNodeMapper;
import com.ysd.lis.service.lab.LabTatNodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * TAT监控节点 服务实现类
 * </p>
 *
 * @author cfz
 * @since 2024-10-24
 */
@Service
public class LabTatNodeServiceImpl extends ServiceImpl<LabTatNodeMapper, LabTatNode> implements LabTatNodeService {
    @Autowired
    LabTatNodeMapper labTatNodeMapper;

    @Override
    public Result findLabTatNodeList(LabTatNode labTatNode) {
        List<LabTatNode> list = findLabTatNodeArray(labTatNode);
        return Result.succ(1, "请求成功", list);
    }

    @Override
    public List<LabTatNode> findLabTatNodeArray(LabTatNode labTatNode) {
        MPJLambdaWrapper<LabTatNode> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.eq(LabTatNode::getDelFlag, 0);
        queryWrapper.eq(StringUtils.isNotBlank(labTatNode.getId()), LabTatNode::getId, labTatNode.getId());
        return labTatNodeMapper.selectList(queryWrapper);
    }

    @Override
    public Result addLabTatNode(LabTatNode labTatNode) {
        int i = labTatNodeMapper.insert(labTatNode);
        if (i > 0) {
            return Result.succ(1, "新增成功", labTatNode);
        }
        return Result.fail("新增失败");
    }

    @Override
    public Result deleteLabTatNode(LabTatNode labTatNode) {
        labTatNode.setDelFlag(1);
        int i = labTatNodeMapper.updateById(labTatNode);
        if (i > 0) {
            return Result.succ(1, "删除成功", labTatNode);
        }
        return Result.fail("删除失败");
    }

    @Override
    public Result updateLabTatNode(LabTatNode labTatNode) {
        int i = labTatNodeMapper.updateById(labTatNode);
        if (i > 0) {
            return Result.succ(1, "更新成功", labTatNode);
        }
        return Result.fail("更新失败");
    }
}
